package main

import (
	"fmt"
	t "./example"
	"github.com/golang/protobuf/proto"
)

func main() {
	var s t.Set
	var ld t.LD

	ld = t.LD{
		Ip: proto.Uint32(666),
	}
	ld_marshalled, _ := proto.Marshal(&ld)
	fmt.Println("encoded ld: ", ld_marshalled)

	s = t.Set{
		Id: proto.Uint32(1), // Id, Name等被变成了大写，且在这初始化中要加上field name ，否则编译不过？？
		Name:proto.String("hello"),
		//LdList: appen
	}

	data, err := proto.Marshal(&s)
	if err != nil {
		fmt.Println(err)
		return
	}

	var decoded t.Set
	err = proto.Unmarshal(data, &decoded)
	if err != nil {
		fmt.Println("decoded failed: ", err)
	}
	fmt.Println("decoded data: ", *decoded.Name, *decoded.Id) //为什么要解引用 ？ decoded不是value型吗
}
